package com.atguigu.spzx.user.service.impl;

import com.atguigu.spzx.user.service.SmsService;
import com.atguigu.spzx.user.utils.SMSUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName: SmsServiceImpl
 * @Package: com.atguigu.spzx.user.service.impl
 * @Description
 * @Author 孤妤
 * @Date: 2023/12/19 11:04
 */
@Service
@Transactional
public class SmsServiceImpl implements SmsService {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
    @Override
    public void sendValidateCode(String phone) {
        String code = RandomStringUtils.randomNumeric(4);
        SMSUtils.sendCode(phone,code);
        redisTemplate.opsForValue().set("user:code:"+phone,code,5, TimeUnit.MINUTES);
    }
}
